package com.example.admindatasource.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.admindatasource.mapper.AlertMapper;
import com.example.admindatasource.mapper.UserMapper;
import com.example.admindatasource.model.po.User;
import com.example.admindatasource.model.vo.DataAndStructVO;
import com.example.admindatasource.service.IVitalModelFileService;
import com.example.adminframework.model.bo.IdBO;
import com.example.adminframework.response.ResultContent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "文件管理")
@RequestMapping(value = "/data_file_manage")
public class ModelFileController {

    @Autowired
    private IVitalModelFileService modelFileService;

    @Resource
    private AlertMapper alertMapper;

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/import")
    @ApiOperation("文件上传")
    public ResultContent<DataAndStructVO> fileUpload(MultipartFile file, HttpServletRequest request) {
        DataAndStructVO dataAndStructVO = modelFileService.fileUpload(file, request);
        return ResultContent.success(dataAndStructVO);
    }


    @PostMapping("/preprocess/update")
    @ApiOperation("数据预处理")
    public ResultContent<DataAndStructVO> preprocess(@RequestBody IdBO startRow, HttpServletRequest request) {
        DataAndStructVO dataAndStructVO = modelFileService.preprocess(startRow.getId(), request);
        return ResultContent.success(dataAndStructVO);
    }



    @PostMapping("/test")
    @ApiOperation("测试")
    public ResultContent test() throws Exception {
        Map<String,Map<String,Integer>> map = new HashMap<>();


        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.select("id");
        List<Object> objects = userMapper.selectObjs(queryWrapper);

        LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper();
        lambdaUpdateWrapper.set("status",1);
        lambdaUpdateWrapper.in("id",objects);

        return ResultContent.success(objects);



    }



}
